import { pwa } from './config/pwa'
import { appDescription, baseURL } from './constants/index'

export default defineNuxtConfig({
  ssr: false,

  modules: [
    '@vueuse/nuxt',
    '@unocss/nuxt',
    '@pinia/nuxt',
    '@pinia-plugin-persistedstate/nuxt',
    '@nuxtjs/color-mode',
    '@vite-pwa/nuxt',
    '@nuxt/eslint',
    '@element-plus/nuxt',
  ],

  experimental: {
    // when using generate, payload js assets included in sw precache manifest
    // but missing on offline, disabling extraction it until fixed
    payloadExtraction: false,
    renderJsonPayloads: true,
    typedPages: true,
  },

  css: [
    '@unocss/reset/tailwind.css',
    'github-markdown-css/github-markdown.css',
    'splitpanes/dist/splitpanes.css',
    '~/assets/common.scss',
  ],

  colorMode: {
    classSuffix: '',
  },

  runtimeConfig: {},

  devServer: {
    host: '0.0.0.0',
    port: 3020,
  },

  nitro: {
    esbuild: {
      options: {
        target: 'esnext',
      },
    },
    prerender: {
      crawlLinks: false,
      routes: ['/'],
      ignore: [],
    },
    // 用于客户端代理
    devProxy: {
      // 登录/登出 接口
      '/api': {
        target: 'http://127.0.0.1/api',
        changeOrigin: true,
        prependPath: true,
      },
     
    },
    // 该配置用于服务端请求转发
    routeRules: {},
  },

  app: {
    baseURL,
    head: {
      viewport: 'width=device-width,initial-scale=1',
      link: [
        { rel: 'icon', href: '/favicon.ico', sizes: 'any' },
        { rel: 'icon', type: 'image/svg+xml', href: '/nuxt.svg' },
        { rel: 'apple-touch-icon', href: '/apple-touch-icon.png' },
      ],
      meta: [
        { name: 'viewport', content: 'width=device-width, initial-scale=1' },
        { name: 'description', content: appDescription },
        { name: 'apple-mobile-web-app-status-bar-style', content: 'black-translucent' },
        { name: 'theme-color', media: '(prefers-color-scheme: light)', content: 'white' },
        { name: 'theme-color', media: '(prefers-color-scheme: dark)', content: '#222222' },
      ],
    },
  },

  pwa,

  devtools: {
    enabled: true,
  },

  features: {
    // For UnoCSS
    inlineStyles: false,
  },

  eslint: {
    config: {
      standalone: false,
    },
  },

  // ... 其他配置
  vite: {
   css: {
     preprocessorOptions: {
       scss: {
         api: 'modern-compiler', // 明确使用 Dart Sass 的现代 API
       },
     },
   },
 },

  compatibilityDate: '2025-06-19',
})